#include "playscene.h"
#include "intro.h"
#include "widget.h"
#include <QMouseEvent>
#include "mypushbotton.h"
#include <QDebug>
#include <QTimer>
#include <QString>
#include "config.h"
#include <iostream>
#include <QGraphicsScene>
#include <QGraphicsTextItem>
#include <QSound>

PlayScene::PlayScene(QWidget *parent) : QMainWindow(parent)
{
    initScene();


    //设置初始分数



    /*score["elation"]=0;
    score["grief"]=0;
    score["peace"]=0;
    score["mania"]=0;*/

    int elation = 0;
    int grief = 0;
    int peace = 0;
    int mania = 0;

    qDebug()<<"elation "<<elation<<"grief "<<grief<<"peace "<<peace<<"mania "<<mania;


    myPushBotton * ice = new myPushBotton(":/resource/ice.png");
    ice->setParent(this);
    ice->move(1300,400);
    connect(ice,&myPushBotton::clicked,[=](){
        QString pos = QString("选取了冰块");
        qDebug() << pos;
        ice->zoom1();
        ice->zoom2();
    connect(ice, SIGNAL(clicked()),this,SLOT(icescore()));
    });


    myPushBotton * lemon = new myPushBotton(":/resource/lemon.png");
    lemon->setParent(this);
    lemon->move(1000,400);
    connect(lemon,&myPushBotton::clicked,[=](){
        lemon->zoom1();
        lemon->zoom2();
    });
    connect(lemon, SIGNAL(clicked()),this,SLOT(lemonscore()));

    myPushBotton * brandy = new myPushBotton(":/resource/brandy.png");
    brandy->setParent(this);
    brandy->move(20,10);
    connect(brandy,&myPushBotton::clicked,[=](){
        brandy->zoom1();
        brandy->zoom2();
    connect(brandy, SIGNAL(clicked()),this,SLOT(brandyscore()));
    });

    myPushBotton * whisky = new myPushBotton(":/resource/whisky.png");
    whisky->setParent(this);
    whisky->move(20,430);
    connect(whisky,&myPushBotton::clicked,[=](){
        whisky->zoom1();
        whisky->zoom2();
    connect(whisky, SIGNAL(clicked()),this,SLOT(whiskyscore()));
    });
    myPushBotton * tequila = new myPushBotton(":/resource/tequila.png");
    tequila->setParent(this);
    tequila->move(200,10);
    connect(tequila,&myPushBotton::clicked,[=](){
        tequila->zoom1();
        tequila->zoom2();
    connect(tequila, SIGNAL(clicked()),this,SLOT(tequilascore()));
    });
    myPushBotton * whiterum = new myPushBotton(":/resource/whiterum.png");
    whiterum->setParent(this);
    whiterum->move(200,430);
    connect(whiterum,&myPushBotton::clicked,[=](){
        whiterum->zoom1();
        whiterum->zoom2();
    connect(whiterum, SIGNAL(clicked()),this,SLOT(whiterumscore()));
    });

    myPushBotton * rum = new myPushBotton(":/resource/rum.png");
    rum->setParent(this);
    rum->move(380,10);
    connect(rum, SIGNAL(clicked()),this,SLOT(rumscore()));
    connect(rum,&myPushBotton::clicked,[=](){
        rum->zoom1();
        rum->zoom2();

    });
    myPushBotton * baileys = new myPushBotton(":/resource/baileys.png");
    baileys->setParent(this);
    baileys->move(380,430);
    connect(baileys, SIGNAL(clicked()),this,SLOT(baileysscore()));
    connect(baileys,&myPushBotton::clicked,[=](){
        baileys->zoom1();
        baileys->zoom2();

    });
    myPushBotton * shaker = new myPushBotton(shaker_img);
    shaker->setParent(this);
    shaker->move((gamew-shaker->width())/2,(gameh-shaker->height())/2);
    connect(shaker,&myPushBotton::clicked,[=](){
        QString act = QString("摇晃了调酒杯");
        qDebug() << act;
        shaker->zoom1();
        shaker->zoom2();
        QSound::play(shaking);

    });
    if(mania>15){
        qDebug() << "These violent delights have violent ends.";
    }
    else if(mania>10||peace<-5){
        qDebug() <<"Whoever fights monsters should see to it that in the process he does not become a monster.";
    }
    else if(elation>0){
        qDebug() << "Fair is foul, and foul is fair.";
    }
    else if (grief>0){
        qDebug() << "Laughter is the root of all evil.";
    }
    if(peace>10){
        qDebug() << "死亡是活过的生命。生活是在路上的死亡。";
    }

}


void PlayScene::initScene()
{
    setFixedSize(gamew,gameh);
    setWindowIcon(QPixmap(gameicon));
    setWindowTitle(gametitle);
}

void PlayScene::rumscore()
{
    grief++;
    peace = peace-2;
    mania++;
    QString pos = QString("选取了朗姆酒,elation: ")+ QString::number(elation)+QString("grief: ")+QString::number(grief) +
            QString("peace")+ QString::number(peace) +QString("mania") +QString::number(mania);
    qDebug() << pos;
    QSound::play(pour);
}

void PlayScene::baileysscore()
{
    grief--;
    peace++;
    QString pos = QString("选取了百利甜,elation: ")+ QString::number(elation)+QString("grief: ")+QString::number(grief) +
            QString("peace")+ QString::number(peace) +QString("mania") +QString::number(mania);
    qDebug() << pos;
    QSound::play(pour);
}

void PlayScene::whiskyscore()
{
    elation = elation+2;
    peace--;
    mania--;
    QString pos = QString("选取了威士忌,elation: ")+ QString::number(elation)+QString("grief: ")+QString::number(grief) +
            QString("peace")+ QString::number(peace) +QString("mania") +QString::number(mania);
    qDebug() << pos;
    QSound::play(pour);
}

void PlayScene::whiterumscore()
{
    elation = elation-2;
    grief++;
    peace--;
    mania = mania+2;
    QString pos = QString("选取了白朗姆,elation: ")+ QString::number(elation)+QString("grief: ")+QString::number(grief) +
            QString("peace")+ QString::number(peace) +QString("mania") +QString::number(mania);
    qDebug() << pos;
    QSound::play(pour);
}

void PlayScene::tequilascore()
{
    elation--;
    grief--;
    peace--;
    mania = mania+3;
    QString pos = QString("选取了龙舌兰,elation: ")+ QString::number(elation)+QString("grief: ")+QString::number(grief) +
            QString("peace")+ QString::number(peace) +QString("mania") +QString::number(mania);
    qDebug() << pos;
    QSound::play(pour);

}

void PlayScene::icescore()
{
    peace=peace+3;
    QSound::play(dropice);
    QString pos = QString("选取了冰块,elation: ")+ QString::number(elation)+QString("grief: ")+QString::number(grief) +
            QString("peace")+ QString::number(peace) +QString("mania") +QString::number(mania);
    qDebug() << pos;


}

void PlayScene::lemonscore()
{
    grief++;
    peace++;
    QString pos = QString("选取了柠檬,elation: ")+ QString::number(elation)+QString("grief: ")+QString::number(grief) +
            QString("peace")+ QString::number(peace) +QString("mania") +QString::number(mania);
    qDebug() << pos;
    QSound::play(droplemon);

}

void PlayScene::brandyscore()
{
    elation++;
    grief = grief-2;
    peace--;
    mania = mania+2;
    QString pos = QString("选取了白兰地,elation: ")+ QString::number(elation)+QString("grief: ")+QString::number(grief) +
            QString("peace")+ QString::number(peace) +QString("mania") +QString::number(mania);
    qDebug() << pos;
    QSound::play(pour);
}
void PlayScene::mousePressEvent(QMouseEvent *ev)
{
    if(ev->button() == Qt::LeftButton)//只有在鼠标左键时才可以捕获
    {
        QString str = QString("鼠标按下了，x=%1 y=%2").arg(ev->x()).arg(ev->y());//globalX是基于屏幕的坐标
        qDebug() << str;
    }
}
void PlayScene::mouseReleaseEvent(QMouseEvent *ev)
{
    if(ev->button() == Qt::LeftButton)//只有在鼠标左键时才可以捕获
    {
        QString str = QString("鼠标释放了，x=%1 y=%2").arg(ev->x()).arg(ev->y());//globalX是基于屏幕的坐标
        qDebug() << str;
    }
}

void PlayScene::paintEvent(QPaintEvent *)
{
    QPainter painter(this);
    QPixmap pix;
    pix.load(":/resource/pub5.jpg");
    painter.drawPixmap(0,0,pix);

}
